import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { configuration } from './config';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
// import { UsersController } from './modules/users/users.controller';
// import { UsersService } from './modules/users/users.service';
import { UsersModule } from './modules/users/users.module';
import { AuthModule } from './common/guard/auth.module';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from './common/guard/auth.guard';
// import { AuthService } from './common/guard/auth.service;
import { OssController } from './modules/oss/oss.controller';
import { OssService } from './modules/oss/oss.service';
import { LxdController } from './modules/lxd/lxd.controller';
import { LxdService } from './modules/lxd/lxd.service';
import { XzkService1, XzkService2, chat1 } from './modules/xzk/xzk.service';
import { XzkController1, XzkController2, chat11 } from './modules/xzk/xzk.controller';
import { LbbController } from './modules/lbb/lbb.controller';
import { LbbService } from './modules/lbb/lbb.service';
import { LkController } from './modules/lk/lk.controller';
import { LkService } from './modules/lk/lk.service';
import { XzyController } from './modules/xzy/xzy.controller';
import { XzyService } from './modules/xzy/xzy.service';
import { ZwcController } from './modules/zwc/zwc.controller';
import { ZwcService } from './modules/zwc/zwc.service';
@Module({
  imports: [
    ConfigModule.forRoot({
      cache: true,
      load: [...configuration.load],
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => {
        const entities = [`${__dirname}/**/*.entity{.ts,.js}`];
        console.log(entities);
        return {
          type: 'mysql',
          ...config.get('db.mysql'),
          entities: [`${__dirname}/**/*.entity{.ts,.js}`],
        } as TypeOrmModuleOptions;
      },
    }),
    UsersModule,
    AuthModule,
  ],
  controllers: [
    OssController,
    LxdController,
    XzkController1,
    chat11,
    XzkController2,
    LbbController,
    LkController,
    XzyController,
    ZwcController,
  ],
  providers: [
    { provide: APP_GUARD, useClass: JwtAuthGuard },
    OssService,
    LxdService,
    XzkService1,
    XzkService2,
    chat1,
    LbbService,
    LkService,
    XzyService,
    ZwcService,
  ],
})
export class AppModule {}
